package com.example.myapplication.ContentTest;

import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import com.example.myapplication.DataBase.DataStoreActivity;
import com.example.myapplication.MainActivity;
import com.example.myapplication.R;
import com.example.myapplication.Services.ServicesTestActivity;

public class ContentActivity extends AppCompatActivity {
  @Override protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.content_provider_layout);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setTitle("ContentProvider实验");
    setSupportActionBar(toolbar);
    SetButtons();
  }

  @Override public boolean onCreateOptionsMenu(Menu menu) {
    menu.add(0, 1, 0, "返回上一个Activity");
    menu.add(0, 2, 1, "跳到下一个Activity");

    return true;
  }

  @Override public boolean onOptionsItemSelected(@NonNull MenuItem item) {
    switch (item.getItemId()) {
      case 1:
        BackToLastActivity();
        break;
      case 2:
        GoToNextActivity();
        break;

    }
    return true;
  }

  private void SetButtons() {
    Button contact = (Button) findViewById(R.id.button_contact);
    Button modify = (Button) findViewById(R.id.modify_button);
    contact.setOnClickListener(new View.OnClickListener() {
      @Override public void onClick(View v) {
        JumpToContact();
      }
    });

    modify.setOnClickListener(new View.OnClickListener() {
      @Override public void onClick(View v) {
        JumpToDictionary();
      }
    });
  }

  private void JumpToDictionary() {
    Intent intent = new Intent(this, DictionaryActivity.class);
    startActivity(intent);
  }

  private void JumpToContact() {
    Intent intent=new Intent(this, ContactInfoActivity.class);
    startActivity(intent);
  }
  private void GoToNextActivity() {
    Intent intent = new Intent(this, ServicesTestActivity.class);
    startActivity(intent);
  }
  private void BackToLastActivity() {
    Intent intent = new Intent(this, DataStoreActivity.class);
    startActivity(intent);

  }
}
